<?php
session_start();
require "lib/db.php";
require "lib/product-function.php";
require "lib/subcategory-function.php";
require "lib/category-function.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Product</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
			$("#product").css({"background-color":"#FFF",	
	"color":"#000"});
    });
</script>

<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:2px 3px;
		opacity:0.8;
		text-align:center;
		}
</style>

</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<!--content-->
<div id="content">
<table width="100%" border="1" cellspacing="0">
  <tr>
    <th colspan="9">List Products</th>
  </tr>
  <tr>
    <th>ProductID</th>
    <th>Category Name</th>
    <th>SubCategory Name</th>
    <th>Product Name</th>
    <th>Price(VND)</th>
    <th>Unit</th>
    <th>Image</th>
    <th>Description</th>
    <th><a href="add-product.php">Add Product</a></th>
  </tr>
  <?php
  $listProduct = getAllProduct();
  while($product = mysql_fetch_array($listProduct)){
	  $subCategoryID = $product['SubCategoryID'];
	  settype( $subCategoryID,"int");
	  $subcategory = mysql_fetch_array(getSubCategoryByID($subCategoryID));
	  $category = mysql_fetch_array(getCategoryBySubCategoryID($subCategoryID));
	   
	  ob_start();
  ?>
  <tr>
    <td>{ProductID}</td>
    <td>{CategoryName}</td>
    <td>{SubCategoryName}</td>
    <td>{ProductName}</td>
    <td>{Price}</td>
    <td>{Unit}</td>
    <td>{Image}</td>
    <td>{Description}</td>
    <td><a href="edit-product.php?productid={ProductID}">Edit</a> - <a onClick="return confirm('Are you sure delete this product?');" href="delete-product.php?productid={ProductID}">Delete</a></td>
  </tr>
  <?php
  $s = ob_get_clean();
  $s = str_replace("{ProductID}","$product[ProductID]",$s);
  $s = str_replace("{CategoryName}","$category[CategoryName]",$s);
  $s = str_replace("{SubCategoryName}","$subcategory[SubCategoryName]",$s);
  $s = str_replace("{ProductName}","$product[ProductName]",$s);
  $s = str_replace("{Price}","$product[Price]",$s);
  $s = str_replace("{Unit}","$product[Unit]",$s);
  $s = str_replace("{Image}","$product[Image]",$s);
  $s = str_replace("{Description}","$product[Description]",$s);
  echo $s;
  }
  ?>
</table>

</div>

<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>